﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ToDoList.Logic
{
   public class ItemLogic
    {
        /// <summary>
        /// 添加备注
        /// </summary>
        /// <param name="InventoryId"></param>
        /// <param name="ItemId"></param>
        /// <param name="Mark"></param>
        /// <returns></returns>
        public bool AddMark(int inventoryId,int itemId,string mark)
        {
            var inventory = Initialize.InventoryList.SingleOrDefault(I => I.InventoryId == inventoryId);
            var item = Initialize.ItemList.SingleOrDefault(I => I.ItemId == itemId);
            if (inventory != null && item != null)
            {
                item.Mark = mark;
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// 添加过期时间
        /// </summary>
        /// <param name="InventoryId"></param>
        /// <param name="ItemId"></param>
        /// <param name="TimeOfExpiration"></param>
        /// <returns></returns>
        public bool AddTimeOfExpiration(int inventoryId, int itemId, DateTime timeOfExpiration)
        {
            var inventory = Initialize.InventoryList.SingleOrDefault(I => I.InventoryId == inventoryId);
            var item = Initialize.ItemList.SingleOrDefault(I => I.ItemId == itemId);
            if (inventory != null && item != null)
            {
                item.TimeOfExpiration = timeOfExpiration;
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// 完成事项
        /// </summary>
        /// <param name="InventoryId"></param>
        /// <param name="ItemId"></param>
        /// <returns></returns>
        public bool Finish(int inventoryId, int itemId)
        {
            var inventory = Initialize.InventoryList.SingleOrDefault(I => I.InventoryId == inventoryId);
            var item = Initialize.ItemList.SingleOrDefault(I => I.ItemId == itemId);
            if (inventory != null && item != null)
            {
                item.State =true;
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// 取消完成
        /// </summary>
        /// <param name="InventoryId"></param>
        /// <param name="ItemId"></param>
        /// <returns></returns>
        public bool Cancel(int inventoryId, int itemId)
        {
            var inventory = Initialize.InventoryList.SingleOrDefault(I => I.InventoryId == inventoryId);
            var item = Initialize.ItemList.SingleOrDefault(I => I.ItemId == itemId);
            if (inventory != null && item != null)
            {
                item.State = false;
                return true;
            }
            else
                return false;
        }
    }
}
